import React, { Component } from 'react';

class ListDialog extends Component {
    constructor(props) {
        super(props);
        this.state = {}
    }
    handleClickAdd = () => {
        let len = this.props.nums;
        let newId = len > 0 ? len : 0;
        let value = this.input.value;
        console.log(value);
        if (value !== '') {
            let obj = {
                id: newId,
                content: value,
                status: 0,
            };
            this.input.value = "";
            this.props.handleAddTask(obj);
        }
        let timeNow = new Date();
        console.log(timeNow);
    }
    enterPress = (event) => {
        if (event.key === 'Enter') {
            this.handleClickAdd(event.target.value)
            event.target.value = ''
        }
    }
    render() {

        return (
            <div className="dialog">
                <div>
                    <h3>任务</h3>
                    <input
                        type="text"
                        ref={input => this.input = input}
                        // defaultValue="安排新的任务吧"
                        onKeyPress={this.enterPress}
                        required="required"
                        autoComplete="off"
                        placeholder="安排新的任务吧……"
                    />
                </div>
                <div>
                    <input type='button'
                        value="保存"
                        onClick={this.handleClickAdd}
                    />
                </div>
            </div>
        );
    }
}

export default ListDialog;